package cn.middle.edge.portal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import com.middle.common.result.UserInfo;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.middle.basic.entity.SysMenu;
import cn.middle.basic.entity.SysRole;
import cn.middle.basic.service.SysUserService;

@Controller
public class IndexController {
	
	
	@Autowired
	private SysUserService userService;
	
	@SaCheckLogin
	@GetMapping({"","/index"})
	public String login(ModelMap modelMap) {
		Long loginId = Long.parseLong((String)StpUtil.getLoginId());
		UserInfo<SysMenu,SysRole> userInfo = this.userService.getUserInfo(loginId);
		StpUtil.getSession().set("name", userInfo.getRealName());
        //通过model传到页面
        modelMap.addAttribute("menuList", userInfo.getMenus());
		return "index";
	}
	
	@SaCheckLogin
	@GetMapping("/welcome")
	public String welcome(ModelMap modelMap) {
		return "welcome";
	}

}